package com.gccloud.design.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gccloud.design.dao.BusinessMgntDao;
import com.gccloud.design.dto.BwpBusinessMgntUpdateSaveDto;
import com.gccloud.design.entity.BusinessMgntEntity;
import com.gccloud.design.service.BusinessMgntService;
import com.gccloud.design.vo.BwpBusinessMgntVo;
import com.gccloud.starter.common.dto.SearchDTO;
import com.gccloud.starter.common.utils.BeanConvertUtils;
import com.gccloud.starter.feign.api.service.ISysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ma.xiulan
 * @date 2021/05/24/ 10:38
 */
@Service
public class BusinessMgntServiceImpl extends ServiceImpl<BusinessMgntDao, BusinessMgntEntity> implements BusinessMgntService {

    @Resource
    private BusinessMgntDao businessMgntDao;

    @Resource
    private ISysUserService iSysUserService;

    @Override
    public int saveBusinessMgnt(BwpBusinessMgntUpdateSaveDto bwpBusinessMgntSaveDto) {
        BusinessMgntEntity businessMgntEntity = BeanConvertUtils.convert(bwpBusinessMgntSaveDto, BusinessMgntEntity.class);
        businessMgntEntity.setCreateUser(iSysUserService.getCurrentUser().getData().getName());
        return businessMgntDao.saveBusinessMgnt(businessMgntEntity);
    }

    @Override
    public Map<String, Object> getBusinessMgnt(Integer id, String logicName, SearchDTO searchDTO) {
        Page<BwpBusinessMgntVo> page = new Page<>();
        page.setCurrent(searchDTO.getCurrent()).setSize(searchDTO.getSize());
        List<BwpBusinessMgntVo> list = businessMgntDao.getBusinessMgnt(id, logicName, page);
        Map<String, Object> map = new HashMap<>(8);
        map.put("list", list);
        map.put("total", page.getTotal());
        return map;
    }

    @Override
    public int deleteBusinessMgnt(Integer id) {
        return businessMgntDao.deleteBusinessMgnt(id);
    }

    @Override
    public int saveUpdateBusinessMgnt(BwpBusinessMgntUpdateSaveDto bwpBusinessMgntSaveDto) {
        BusinessMgntEntity businessMgntEntity = BeanConvertUtils.convert(bwpBusinessMgntSaveDto, BusinessMgntEntity.class);
        businessMgntEntity.setModUser(iSysUserService.getCurrentUser().getData().getName());
        return businessMgntDao.saveUpdateBusinessMgnt(businessMgntEntity);

    }
}
